package interfaz;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.TexturePaint;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class JPanelImagen extends JPanel {
	
	private static final long serialVersionUID = 1L;
	private String rutaImagen;
	
	public JPanelImagen(String rutaImagen, LayoutManager layout){
		super(layout);
		this.rutaImagen = rutaImagen;
		setOpaque(false);
	}

	@Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        try {
			g2d.setPaint(new TexturePaint(ImageIO.read(new File(rutaImagen)), new Rectangle(0, 0, getWidth(),getHeight())));
			g2d.fillRect(0, 0, getWidth(), getHeight());
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
	public static GridBagConstraints dameGridConPading(int pading){
		GridBagConstraints grid = new GridBagConstraints();
		grid.insets = new Insets(pading, pading, pading, pading);
		return grid;
	}

}
